import React, {
  Component,
} from "react";
import {
  Text,
  TouchableOpacity,
  TouchableWithoutFeedback,
  View,
  Linking,
} from "react-native";
import {
  platform
} from "../../baseData";

import styles from "./task-details-sheet";

export default function TaskDetails(props) {
  const jumpURL = url => {
    Linking.canOpenURL(url).then((supported) => {
      if (!supported) {
        global.showToast('链接不存在');
      } else {
        return Linking.openURL(url);
      }
    }).catch((e) => {
      global.showToast(e);
    });
  }

  return (
    <View style={styles.content}>
      <View style={[styles.row, {marginTop: 0}]}>
        <Text style={styles.title}>平台: </Text>
        <Text style={styles.contentText}>{platform[props.platform].name}</Text>
      </View>
      <View style={styles.row}>
        <Text style={styles.title}>类型: </Text>
        <Text style={styles.contentText}>{props.name}</Text>
      </View>
      <View style={styles.row}>
        <Text style={styles.title}>单价: </Text>
        <Text style={styles.contentText}>{(props.reward / 100).toFixed(1)}豆子</Text>
      </View>
      <View style={styles.row}>
        <Text style={styles.title}>链接: </Text>
        <TouchableWithoutFeedback onPress={()=>jumpURL(props.url)}>
            <Text style={[styles.contentText, {color: "blue"}]}>点击这里</Text>
        </TouchableWithoutFeedback>
      </View>
      <View style={styles.row}>
        <Text style={styles.title}>方向: </Text>
        <Text style={styles.contentText}>{props.desc}</Text>
      </View>
      <View style={styles.row}>
        <Text style={styles.title}>备注: </Text>
        <Text style={styles.contentText}>{props.remark?props.remark:'无'}</Text>
      </View>
    </View>
  )
}